-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show the admin/settings menu for any of its elements #3783
Show the admin/settings menu for any of its elements #3783
Conversation
e7bc874
to
6e20af2
Compare
view = double("view", can?: false) | ||
expect(view).to receive(:can?).at_least(12).times | ||
view.instance_exec(&menu_item.condition) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to test the result of view.instance_exec(&menu_item.condition)
in a couple of different scenarios? With your current test, one could change all the ||
to &&
and still have the test pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course, this is a trade-off between simplicity and completeness. Although I think the change to &&
would make the test fail (can?
would be called just once), I see the point, I'm just not sure how much more detail we want to put in there, given the complete matrix in all its combinations is probably too much.
I think the real fix would be to redesign the admin menu items to have sub-items wrapped in objects and check if any of those is #visible?
, but this is clearly beyond the scope of this PR.
That'd be fine if I opened an issue describing the underlying problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I think the change to && would make the test fail (can? would be called just once)
Right, my bad. 🤦
I think the real fix would be to redesign the admin menu items to have sub-items wrapped in objects and check if any of those is #visible?, but this is clearly beyond the scope of this PR.
Agreed that it would be better. Feel free to open an issue.
I see the point, I'm just not sure how much more detail we want to put in there, given the complete matrix in all its combinations is probably too much.
I feel like we could do a bit better than the current implementation without writing too much additional code.
A good compromise could be just two tests such as the following:
it 'is shown if any of its submenus are present' do
view = double("view")
allow(view).to receive(:can?).and_return(true, false)
result = view.instance_exec(&menu_item.condition)
expect(result).to eq(true)
end
it 'is not shown if none of its submenus are present' do
view = double("view", can?: false)
result = view.instance_exec(&menu_item.condition)
expect(result).to eq(false)
end
The main benefits over the existing tests, in my opinion, are:
- You're testing the underlying logic more directly. Rather than setting an expectation on how many times
can?
is called, you're setting it on whether the condition works properly. - The tests are more expressive. Reading your test, it's unclear how the underlying implementation works. With this version, it's a bit clearer what's going on in the implementation.
- The tests follow a standard setup/exercise/verify pattern and are easier for a human to parse. The origin.al test mixed setup and expectations by using
expect(view).to receive(...)
.
Let me know your thoughts!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion, it was useful!
The issue is here #3785
It's possible to create permission sets the only give access to a subset of the settings menu items, without this the settings menu was kept hidden.
6e20af2
to
295df5e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @elia!
Description
It's possible to create permission sets the only give access to a
subset of the settings menu items, without this the settings menu was
kept hidden.
Checklist: